/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package controls;

import com.aptech.bluepumpkin.Faq;
import com.aptech.bluepumpkin.beans.FaqFacade;
import java.util.List;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;

/**
 *
 * @author Chien
 */
@ManagedBean
@SessionScoped
public class FaqControl {

    @EJB
    private FaqFacade faqFacade;
    private Faq faq;
    private Faq selectedFaq;

    public List<Faq> getAllFQAs(){
       return faqFacade.findAll();
    }
    public void redirectToAddFAQ() {

        FacesContext context = FacesContext.getCurrentInstance();
        String path = context.getExternalContext().getRequestContextPath() + "/faces/admin/faq/addFAQ.xhtml";
        utils.Uility.redirectPage(context, null, path);
    }

    public void redirectToListFAQs() {

        FacesContext context = FacesContext.getCurrentInstance();
        String path = context.getExternalContext().getRequestContextPath() + "/faces/admin/faq/faqsPage.xhtml";
        utils.Uility.redirectPage(context, null, path);
    }
    public void redirectToFAQDetails() {

        FacesContext context = FacesContext.getCurrentInstance();
        String path = context.getExternalContext().getRequestContextPath() + "/faces/admin/faq/faqDeatails.xhtml";
        utils.Uility.redirectPage(context, null, path);
    }
    public void redirectToEditFAQ
            () {

        FacesContext context = FacesContext.getCurrentInstance();
        String path = context.getExternalContext().getRequestContextPath() + "/faces/admin/faq/editFAQ.xhtml";
        utils.Uility.redirectPage(context, null, path);
    }

    /**
     * Creates a new instance of FaqControl
     */
    public FaqControl() {
        faq = new Faq();
        selectedFaq = new Faq();
    }

   

    public void delete(Faq faq) {

        faqFacade.remove(faq);
        
    }
public void updateFAQ( Faq faq){
    selectedFaq =faq;
    redirectToEditFAQ();
}
    public void update() {
        
        faqFacade.edit(selectedFaq);
        redirectToListFAQs();

    }

    public void insert() {

        faqFacade.create(faq);
        faq = new Faq();
        redirectToListFAQs();

    }

    


    public Faq getFaq() {
        return faq;
    }

    public void setFaq(Faq faq) {
        this.faq = faq;
    }

    public Faq getSelectedFaq() {
        return selectedFaq;
    }

    public void setSelectedFaq(Faq selectedFaq) {
        this.selectedFaq = selectedFaq;
    }

    public List<Faq> findAll() {
        return faqFacade.findAll();
    }

    public Faq getdetail() {
        return faq;
    }

    public Faq selectedFaq() {
        return selectedFaq;
    }

    public void selectedFaq(Faq selectedFaq) {
        this.selectedFaq = selectedFaq;
    }
}
